package org.szy.anon.controller;

import cn.dev33.satoken.stp.StpUtil;
import org.noear.solon.annotation.*;
import org.noear.solon.core.handle.ModelAndView;
import org.szy.anon.pojo.LoginBodyParam;
import org.szy.anon.service.AnonService;
import org.szy.core.common.controller.BaseController;
import org.szy.core.common.entity.R;

import java.util.Map;

/**
 * 不拦截控制器
 *
 * @author 孙志阳
 * @date 2023-02-16
 * @since 1.0.0
 **/
@Controller
@Mapping("/anon")
public class AnonController extends BaseController {

    private final String PATH_PREFIX = "anon/";
    @Inject
    private AnonService anonService;

    @Get
    @Mapping("/login")
    public ModelAndView login() {
        return new ModelAndView(PATH_PREFIX + "login");
    }

    /**
     * 登录
     *
     * @param loginBodyParam
     * @return
     */
    @Post
    @Mapping("/login")
    public R<?> login(LoginBodyParam loginBodyParam) {
        Map<String, String> map = anonService.login(loginBodyParam);
        return R.data(map);
    }

    @Delete
    @Mapping("/logout")
    public R<?> logout() {
        StpUtil.logout();
        return R.ok();
    }


}
